import java.util.Scanner;

public class Test2 {
    private static int ret;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            in.nextLine();
            for (int i = 0; i < n; i++) {
                ret = 0x3f3f3f3f;
                int num = in.nextInt();
                in.nextLine();
                if (num % 2 == 0) {
                    System.out.println(num-1);
                    return;
                }
                dfs(num-1, 1, 1);
                System.out.println(ret);
            }
        }
    }

    private static void dfs(int num ,int dev, int path) {
        if (num <= 0) {
            if (num == 0) {
                ret = Math.min(ret, path);
            }
            return;
        }
        dfs(num-dev, dev, path+1);
        dfs(num-2*dev, dev*2, path+1);
    }
}
